package com.cvmars.jianyou.module.base;

import android.app.ActivityOptions;
import android.app.Dialog;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.view.View;

import com.cvmars.jianyou.R;
import com.cvmars.jianyou.module.activity.PersonHomeActivity;
import com.wang.avi.AVLoadingIndicatorView;

/**
 * Created by hehaifeng on 2018/6/10.
 */

public class BaseFragment extends Fragment {
    Dialog prodialog;

    // 关闭加载框
    public void getLoadDialogAndShow() {
        getLoadDialog().show();

        if (indicatorView != null) {
            indicatorView.show();
        }
    }

    // 关闭加载框
    public void getLoadDialogAndDismiss() {
        if (prodialog != null && prodialog.isShowing()) {
            if (indicatorView != null) {
                indicatorView.hide();
            }

            getLoadDialog().dismiss();
        }
    }

    AVLoadingIndicatorView indicatorView;

    // 获取加载框
    public Dialog getLoadDialog() {

        if (prodialog == null) {
            prodialog = new Dialog(getContext(), R.style.load_animate_dialog);
            View view = getLayoutInflater().inflate(R.layout._loading_dialog,
                    null);
            indicatorView = view.findViewById(R.id.loading);
            indicatorView.show();
            prodialog.setContentView(view);
        }
        return prodialog;
    }


    private void onGoHome(String id) {

        Intent intent = new Intent(getActivity(),
                PersonHomeActivity.class);
        intent.putExtra("userid", id);
        startActivity(intent);
    }

}
